#pragma strict

var percent:float = 0;

var texture:Texture2D;

private var width:int = 100;
private var height:int = 1; 
private var lastPercent:float;

function Start () {
	texture = new Texture2D(width,height);
	renderer.material.SetTexture("_Mask",texture);
}

function Update () {
	if(lastPercent != percent){
		percent = Mathf.Clamp(percent,0,1);
		//alpah置为0
		var colors:Color[] = texture.GetPixels();
		for(var c:Color in colors){
			c.a = 0;
		}
		texture.SetPixels(colors);
		texture.Apply(false);
		//alpha置为1
		colors = texture.GetPixels(0,0,width* percent,height,0);
		for(c in colors){
			c.a = 1;
		}
		texture.SetPixels(0,0,width * percent,height,colors);
		texture.Apply(false);
		
		lastPercent = percent;
	}
}
